package com.siwei.mes.service.erp.impl;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.siwei.mes.common.base.BaseParams;
import com.siwei.mes.common.util.ConvertUtils;
import com.siwei.mes.common.util.DateHelper;
import com.siwei.mes.common.util.JsonUtils;
import com.siwei.mes.common.util.MacTools;
import com.siwei.mes.common.util.*;
import com.siwei.mes.config.CompanyConfigInterceptor;
import com.siwei.mes.controller.common.UploadController;
import com.siwei.mes.entity.dto.ExportRwdextraPrintDto;
import com.siwei.mes.entity.dto.RwdextraDto;
import com.siwei.mes.entity.dto.RwdextraVolDto;
import com.siwei.mes.entity.erp.Rwdextra;
import com.siwei.mes.entity.erp.RwdextraExtend;
import com.siwei.mes.entity.erp.RwdextraInfo;
import com.siwei.mes.entity.erp.RwdextraPrintInfo;
import com.siwei.mes.entity.experiment.Experiment;
import com.siwei.mes.entity.experiment.ExperimentDetail;
import com.siwei.mes.entity.experiment.concrete.batch.ConcreteKyqd;
import com.siwei.mes.entity.mixproportion.MixProportion;
import com.siwei.mes.entity.mixproportion.MixProportionReport;
import com.siwei.mes.entity.system.CompanyConfig;
import com.siwei.mes.enums.CheckEnum;
import com.siwei.mes.enums.TestProjectEnum;
import com.siwei.mes.mapper.erp.RwdextraExtendMapper;
import com.siwei.mes.mapper.erp.RwdextraMapper;
import com.siwei.mes.mapper.experiment.ExperimentDetailMapper;
import com.siwei.mes.mapper.experiment.ExperimentMapper;
import com.siwei.mes.service.erp.RwdextraExportService;
import com.siwei.mes.service.erp.RwdextraExtendService;
import com.siwei.mes.service.erp.RwdextraService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * ERP-生产任务(Rwdextra)表服务接口
 *
 * @author linzi
 * @since 2024-07-29 16:13:33
 */
@Slf4j
@Service
public class RwdextraExportServiceImpl implements RwdextraExportService {
    @Value(value = "${excel.mac}")
    private String ADDRESS_MAC;
    @Value(value = "${excel.windows}")
    private String ADDRESS_WINDOWS;
    @Value(value = "${excel.linux}")
    private String ADDRESS_LINUX;
    @Value(value = "${server.port}")
    private String port;
    @Resource
    private RwdextraService rwdextraService;
    @Resource
    private RwdextraMapper rwdextraMapper;
    @Resource
    private RwdextraExtendMapper rwdextraExtendMapper;
    @Resource
    private ExperimentDetailMapper experimentDetailMapper;
    @Resource
    private ExperimentMapper experimentMapper;
    @Resource
    private RwdextraExtendService rwdextraExtendService;

    @Override
    public String exportRwdextra(Rwdextra entity, HttpServletRequest request) {
        // 准备数据
        List<Rwdextra> list = rwdextraService.getAll(entity);
        assertTrue(CollectionUtil.isEmpty(list), "未查询到任务单");
        CompanyConfig companyConfig = CompanyConfigInterceptor.getCompanyConfig(1);
        List<RwdextraDto> data1 = new ArrayList<>();
        List<RwdextraVolDto> data2 = new ArrayList<>();
        for (Rwdextra rwdextra : list) {
            RwdextraDto rwdextraDto = new RwdextraDto();
            // 设置其他字段
            rwdextraDto.setCommissionDate(rwdextra.getPlantime());
            RwdextraInfo rwdextraInfo = rwdextra.getRwdextraInfo();
            rwdextraDto.setProductionVolume(rwdextra.getFhquantity());
            rwdextraDto.setRemark(rwdextra.getRedreason());
            if (rwdextraInfo != null) {
                rwdextraDto.setTaskNumber(rwdextraInfo.getFRwno());
                rwdextraDto.setProjectName(rwdextraInfo.getFGcmc());
                rwdextraDto.setConstructionPart(rwdextraInfo.getFJzbw());
                rwdextraDto.setConstructionUnit(rwdextraInfo.getFHtdw());
                rwdextraDto.setDesignStrengthGrade(rwdextraInfo.getFTpz());
                rwdextraDto.setWaterResistanceGrade(rwdextraInfo.getKsdj());
                rwdextraDto.setFlexuralStrengthGrade(ConvertUtils.getMesTpzToKzyq(rwdextraInfo.getFTpz()));
                rwdextraDto.setGradationNumber(rwdextra.getPhbshow());
                rwdextraDto.setSlump(rwdextraInfo.getFTld());
                rwdextraDto.setPlannedVolume(rwdextraInfo.getFJhsl());
                String kllz = rwdextraInfo.getKllz();
                if (StringUtils.isNotBlank(kllz)) {
                    rwdextraDto.setChlorideControlIndex("氯离子含量≤" + kllz + "%");
                }
            }
            //配合比相关,从扩展表中获取
            RwdextraExtend rwdextraExtend = rwdextraExtendMapper.selectByFRwdh(rwdextra.getFrwdh());
            if (rwdextraExtend != null) {
                RwdextraPrintInfo rwdextraPrintInfo = JsonUtils.getObject(rwdextraExtend.getPrintJson(), RwdextraPrintInfo.class);
                if (rwdextraPrintInfo != null) {
                    MixProportion mixProportion = rwdextraPrintInfo.getMixProportionInfo();
                    if (mixProportion != null) {
                        MixProportionReport mixProportionReport = JsonUtils.getObject(mixProportion.getProportionMaterial(), MixProportionReport.class);
                        if (mixProportionReport != null) {
                            MixProportionReport.BgxxInfo water = mixProportionReport.getWater();
                            rwdextraDto.setWaterUsage(water.getDyyl());
                            /** 水泥 **/
                            MixProportionReport.BgxxInfo sn = mixProportionReport.getSn();
                            setCjOrGys(companyConfig.getSnConfig(), sn);
                            rwdextraDto.setCementManufacturer(sn.getCj());
                            rwdextraDto.setCementUsage(sn.getDyyl());
                            rwdextraDto.setCementReportNumber(sn.getXhbgbh());
                            rwdextraDto.setCementQualityCertificateNumber(sn.getBatch());
                            rwdextraDto.setCementCertificateNo(sn.getCertificateNo());
                            /** 矿渣粉 **/
                            MixProportionReport.BgxxInfo kzf = mixProportionReport.getKzf();
                            setCjOrGys(companyConfig.getKzfConfig(), kzf);
                            rwdextraDto.setMineralPowder(kzf.getCj());
                            rwdextraDto.setMineralPowderUsage(kzf.getDyyl());
                            rwdextraDto.setMineralPowderReportNumber(kzf.getXhbgbh());
                            rwdextraDto.setMineralPowderQualityCertificateNumber(kzf.getBatch());
                            rwdextraDto.setMineralCertificateNo(kzf.getCertificateNo());
                            /** 粉煤灰 **/
                            MixProportionReport.BgxxInfo fmh = mixProportionReport.getFmh();
                            setCjOrGys(companyConfig.getFmhConfig(), fmh);
                            rwdextraDto.setFlyAsh(fmh.getCj());
                            rwdextraDto.setFlyAshUsage(fmh.getDyyl());
                            rwdextraDto.setFlyAshReportNumber(fmh.getXhbgbh());
                            rwdextraDto.setFlyAshQualityCertificateNumber(fmh.getBatch());
                            rwdextraDto.setFlyAshCertificateNo(fmh.getCertificateNo());
                            /** 细骨料 **/
                            MixProportionReport.BgxxInfo xgl = mixProportionReport.getXgl();
                            setCjOrGys(companyConfig.getXglConfig(), xgl);
                            rwdextraDto.setSand(xgl.getCj());
                            rwdextraDto.setFineAggregateUsage(xgl.getDyyl());
                            rwdextraDto.setFineAggregateReportNumber(xgl.getXhbgbh());
                            rwdextraDto.setFineAggregateQualityCertificateNumber(xgl.getBatch());
                            rwdextraDto.setFineAggregateCertificateNo(xgl.getCertificateNo());
                            /** 粗骨料 **/
                            MixProportionReport.BgxxInfo cgl = mixProportionReport.getCgl();
                            setCjOrGys(companyConfig.getCglConfig(), cgl);
                            rwdextraDto.setGravel(cgl.getCj());
                            rwdextraDto.setCoarseAggregateUsage(cgl.getDyyl());
                            rwdextraDto.setCoarseAggregateReportNumber(cgl.getXhbgbh());
                            rwdextraDto.setCoarseAggregateQualityCertificateNumber(cgl.getBatch());
                            rwdextraDto.setAggregateSize(cgl.getWlgg().replace("-", "~"));
                            rwdextraDto.setCoarseAggregateCertificateNo(cgl.getCertificateNo());
                            /** 外加剂1 **/
                            MixProportionReport.BgxxInfo wjj1 = mixProportionReport.getWjj1();
                            setCjOrGys(companyConfig.getWjjConfig(), wjj1);
                            rwdextraDto.setAdmixture(wjj1.getCj());
                            rwdextraDto.setAdmixtureUsage(wjj1.getDyyl());
                            rwdextraDto.setAdmixtureReportNumber(wjj1.getXhbgbh());
                            rwdextraDto.setAdmixtureQualityCertificateNumber(wjj1.getBatch());
                            rwdextraDto.setAdmixtureCertificateNo(wjj1.getCertificateNo());
                            /** 外掺料1 **/
                            MixProportionReport.BgxxInfo wcl1 = mixProportionReport.getWcl1();
                            setCjOrGys(companyConfig.getWcl1Config(), wcl1);
                            rwdextraDto.setAdditive1(wcl1.getCj());
                            rwdextraDto.setAdditive1Usage(wcl1.getDyyl());
                            /** 外掺料2 **/
                            MixProportionReport.BgxxInfo wcl2 = mixProportionReport.getWcl2();
                            setCjOrGys(companyConfig.getWcl2Config(), wcl2);
                            rwdextraDto.setAdditive2(wcl2.getCj());
                            rwdextraDto.setAdditive2Usage(wcl2.getDyyl());
                        }
                        rwdextraDto.setAge("R" + mixProportion.getProportionLq());
                    }
                    int con = 1;
                    List<RwdextraPrintInfo.Kytz> kytzList = rwdextraPrintInfo.getKyInfoList();
                    if (CollectionUtil.isNotEmpty(kytzList)) {
                        String ypbh = null;
                        for (RwdextraPrintInfo.Kytz kytz : kytzList) {
                            if (StringUtils.isNotBlank(kytz.getSytzbh())) {
                                Experiment experiment = experimentMapper.loadById(Long.valueOf(kytz.getSytzbh()));
                                if (experiment != null) {
                                    ypbh = experiment.getSampleId();
                                    List<ExperimentDetail> experimentDetailList = experimentDetailMapper.selectByExperimentId(Long.valueOf(kytz.getSytzbh()), TestProjectEnum.CONCRETE_PARAM_KYQD.getCode());
                                    if (CollectionUtil.isNotEmpty(experimentDetailList)) {
                                        ConcreteKyqd concreteKyqd = experimentDetailList.get(0).getObjJson().toJavaObject(ConcreteKyqd.class);
                                        RwdextraVolDto rwdextraVolDto = new RwdextraVolDto();
                                        rwdextraVolDto.setTaskNumber(rwdextraInfo.getFRwno());
                                        rwdextraVolDto.setBlockNumber(ypbh);
                                        rwdextraVolDto.setLoad1(roundToOneDecimalPlace(concreteKyqd.getQd28d().get(0).getQd(), 1));
                                        rwdextraVolDto.setLoad2(roundToOneDecimalPlace(concreteKyqd.getQd28d().get(1).getQd(), 1));
                                        rwdextraVolDto.setLoad3(roundToOneDecimalPlace(concreteKyqd.getQd28d().get(2).getQd(), 1));
                                        rwdextraVolDto.setAverage(roundToOneDecimalPlace(concreteKyqd.getPjz28d(), 1));
                                        rwdextraVolDto.setStandard(roundToOneDecimalPlace(concreteKyqd.getZsbzqd28d(), 1));
                                        rwdextraVolDto.setPercentage(roundToOneDecimalPlace(concreteKyqd.getFyxs28d(), 0));
                                        rwdextraVolDto.setPlantime(rwdextra.getPlantime());
                                        data2.add(rwdextraVolDto);
                                    }
                                }
                            }
                            if (con == 1) {
                                rwdextraDto.setTestBlockNumber1(ypbh);
                            }
                            if (con == 2) {
                                rwdextraDto.setTestBlockNumber2(ypbh);
                            }
                            if (con == 3) {
                                rwdextraDto.setTestBlockNumber3(ypbh);
                            }
                            if (con == 4) {
                                rwdextraDto.setTestBlockNumber4(ypbh);
                            }
                            if (con == 5) {
                                rwdextraDto.setTestBlockNumber5(ypbh);
                            }
                            if (con == 6) {
                                rwdextraDto.setTestBlockNumber6(ypbh);
                            }
                            if (con == 7) {
                                rwdextraDto.setTestBlockNumber7(ypbh);
                            }
                            if (con == 8) {
                                rwdextraDto.setTestBlockNumber8(ypbh);
                            }
                            if (con == 9) {
                                rwdextraDto.setTestBlockNumber9(ypbh);
                            }
                            if (con == 10) {
                                rwdextraDto.setTestBlockNumber10(ypbh);
                            }
                            if (con == 11) {
                                rwdextraDto.setTestBlockNumber11(ypbh);
                            }
                            con++;
                        }
                    }
                    /** 抗渗 只取一个 默认取计划时间最近一次试验台账**/
                    List<Long> ksExperimentIdList = experimentDetailMapper.selectExperimentIdByTestProjectCode(rwdextra.getFrwdh(), CheckEnum.BATCH.getCode(), TestProjectEnum.CONCRETE_PARAM_KSDJ.getCode());
                    if (!ksExperimentIdList.isEmpty()) {
                        Experiment experiment = experimentMapper.loadById(ksExperimentIdList.get(0));
                        rwdextraDto.setWaterResistanceNumber(experiment.getSampleId());
                    }
                    /** 抗折 只取一个 默认取计划时间最近一次试验台账**/
                    List<Long> kzExperimentIdList = experimentDetailMapper.selectExperimentIdByTestProjectCode(rwdextra.getFrwdh(), CheckEnum.BATCH.getCode(), TestProjectEnum.CONCRETE_PARAM_KZQD.getCode());
                    if (!kzExperimentIdList.isEmpty()) {
                        Experiment experiment = experimentMapper.loadById(kzExperimentIdList.get(0));
                        rwdextraDto.setFlexuralNumber(experiment.getSampleId());
                    }
                }
                if (StringUtils.isNotBlank(rwdextraExtend.getQualityCertificateNo())) {
                    rwdextraDto.setCertificateNumber(DateHelper.getDateByYearTwo() + rwdextraExtend.getQualityCertificateNo());
                }
            }
            data1.add(rwdextraDto);
        }

        if (data1 == null) {
            data1 = new ArrayList<>();
        }

        if (data2 == null) {
            data2 = new ArrayList<>();
        }

        List<RwdextraDto> dataList1 = data1.stream()
                .sorted(Comparator.comparing(RwdextraDto::getTaskNumber))
                .collect(Collectors.toList());

        List<RwdextraVolDto> dataList2 = data2.stream()
                .sorted(Comparator.comparing(RwdextraVolDto::getTaskNumber))
                .collect(Collectors.toList());

        // 设置第一个Sheet的导出参数
        ExportParams sheet1Params = new ExportParams();
        sheet1Params.setSheetName("生产日志"); // 设置第一个Sheet的名称

        // 设置第二个Sheet的导出参数
        ExportParams sheet2Params = new ExportParams();
        sheet2Params.setSheetName("强度记录"); // 设置第二个Sheet的名称

        // 设置导出参数
        List<Map<String, Object>> sheetsList = new ArrayList<>();

        // 第一个Sheet配置
        Map<String, Object> sheet1Map = new HashMap<>();
        sheet1Map.put("title", sheet1Params);
        sheet1Map.put("entity", RwdextraDto.class);
        sheet1Map.put("data", dataList1);
        sheetsList.add(sheet1Map);

        // 第二个Sheet配置
        Map<String, Object> sheet2Map = new HashMap<>();
        sheet2Map.put("title", sheet2Params);
        sheet2Map.put("entity", RwdextraVolDto.class); // 如果结构不同，替换为其他DTO类
        sheet2Map.put("data", dataList2);
        sheetsList.add(sheet2Map);


        // 执行导出，生成包含两个Sheet的Workbook
        Workbook workbook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.XSSF);
        Sheet sheet = workbook.getSheetAt(1);
        if (sheet != null) {
            Row headerRow = sheet.getRow(0); // 假设父级表头在第一行
            for (Cell cell : headerRow) {
                if ("占位符".equals(cell.getStringCellValue())) {
                    cell.setCellValue(""); // 清空内容
                }
            }
            // 合并第一行的“抗压强度”相关的三个单元格
            sheet.addMergedRegionUnsafe(new CellRangeAddress(1, 1, 2, 4));
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String str = "生产日志" + sdf.format(new Date());

        /**获取盘符地址*/
        String pathName = getPathName();
        String filePath = pathName + str + ".xlsx";
        String fileName = str + ".xlsx";
        //将excel 写入到服务器地址
        try {
            /**判断目录是否存在*/
            File saveFile = new File(pathName);
            if (!saveFile.exists()) {
                saveFile.mkdirs();
            }

            FileOutputStream fos = new FileOutputStream(filePath);
            workbook.write(fos);
            fos.close();//关闭流

            /**获取可访问的excel地址*/
            String urlPath = UploadController.replacePathExcel(fileName, request, port);
            log.info("上传excel文件成功,路径：{},excel名称：{}", urlPath, fileName);

            return urlPath;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("数据导出失败" + e);
        }
        return null;
    }

    @Override
    public ExportRwdextraPrintDto exportRwdextraPrint(Rwdextra entity) {
        ExportRwdextraPrintDto rwdextraPrintDto = new ExportRwdextraPrintDto();
        List<ExportRwdextraPrintDto.PrintDateList> printDateLists = new ArrayList();
        List<Date> dates = rwdextraMapper.getPlanTimeList(entity);
        for (Date date: dates) {
            ExportRwdextraPrintDto.PrintDateList printDateList = new ExportRwdextraPrintDto.PrintDateList();
            printDateList.setRwdextraTime(date);
            Rwdextra dateEntity = new Rwdextra();
            BeanUtil.copyProperties(entity,dateEntity);
            dateEntity.setPlantimeStart(DateHelper.formatDateTime(date));
            dateEntity.setPlantimeEnd(DateHelper.formatDateTime(date));
            List<Rwdextra> rwdextraList = rwdextraMapper.getPlanTimeDateList(dateEntity);
            this.payloadOtherInfoList(rwdextraList);
            List<ExportRwdextraPrintDto.RwdextraList> rwdextraDateList = new ArrayList();
            for (Rwdextra rwdextra:rwdextraList) {
                ExportRwdextraPrintDto.RwdextraList rwdextraDate = new ExportRwdextraPrintDto.RwdextraList();
                RwdextraInfo rwdextraInfo = RwdextraInfo.jsonToObj(rwdextra.getExtrainfo());
                rwdextraDate.setFrwdh(rwdextra.getFrwdh());
                rwdextraDate.setDesignStrengthGrade(rwdextraInfo.getFTpz());
                rwdextraDate.setTaskNumber(rwdextraInfo.getFRwno());
                rwdextraDate.setConstructionUnit(rwdextraInfo.getFHtdw());
                rwdextraDate.setProjectName(rwdextraInfo.getFGcmc());
                rwdextraDate.setConstructionPart(rwdextraInfo.getFJzbw());
                rwdextraDate.setPhbNumber(rwdextraInfo.getFPhbNo());
                rwdextraDate.setProductionVolume(rwdextra.getFhquantity());
                if(rwdextra.getRwdextraExtend() != null){
                    RwdextraPrintInfo rwdextraPrintInfo = JsonUtils.getObject(rwdextra.getRwdextraExtend().getPrintJson(), RwdextraPrintInfo.class);
                    if(rwdextraPrintInfo != null){
                        if(CollectionUtil.isNotEmpty(rwdextraPrintInfo.getKytzList())){
                            rwdextraDate.setKyList(rwdextraPrintInfo.getKytzList());
                        }
                        if(StringUtils.isNotBlank(rwdextraPrintInfo.getKstzypbh())){
                            List<String> ksSampleIdList = new ArrayList();
                            ksSampleIdList.add(rwdextraPrintInfo.getKstzypbh());
                            rwdextraDate.setKsList(ksSampleIdList);
                        }
                    }

                }
                rwdextraDateList.add(rwdextraDate);
            }
            printDateList.setRwdextraList(rwdextraDateList);
            printDateLists.add(printDateList);
        }
        rwdextraPrintDto.setPrintDateList(printDateLists);
        /**企业配置信息*/
        CompanyConfig companyConfig = CompanyConfigInterceptor.getCompanyConfig(1);
        rwdextraPrintDto.setCompanyName(companyConfig.getCompanyName());
        return rwdextraPrintDto;
    }


    /**
     * 组装其它信息
     *
     * @param list
     */
    private void payloadOtherInfoList(List<Rwdextra> list) {
        if (list.isEmpty()) {
            return;
        }
        /**这里获取所有的任务单唯一标识*/
        Set<Integer> frwdList = new HashSet<>();
        for (Rwdextra rwdextra : list) {
            frwdList.add(rwdextra.getFrwdh());
        }

        /**查询所有品控扩展信息*/
        Map<Integer, RwdextraExtend> rwdextraExtendMap = rwdextraExtendService.getRwdextraExtendMap(frwdList);
        for (Rwdextra rwdextra : list) {
            try {
                Integer frwdh = rwdextra.getFrwdh();
                /**这里查询品控扩展信息*/
                RwdextraExtend rwdextraExtend = rwdextraExtendMap.get(frwdh);
                if (rwdextraExtend != null) {
                    rwdextra.setProduceId(rwdextraExtend.getProduceId());
                    rwdextra.setProduceIndexId(rwdextraExtend.getProduceIndexId());
                    rwdextra.setConsignId(rwdextraExtend.getConsignId());
                    rwdextra.setPrintStatus(NullUtils.ifNullInteger(rwdextraExtend.getPrintStatus(), 0));
                    String projectName = rwdextraExtend.getProjectName();
                    String contractName = rwdextraExtend.getContractName();
                    String buildName = rwdextraExtend.getBuildName();
                    if (org.apache.commons.lang.StringUtils.isNotBlank(projectName)) {
                        rwdextra.setProjectNameNew(projectName);
                    }
                    if (org.apache.commons.lang.StringUtils.isNotBlank(contractName)) {
                        rwdextra.setContractNameNew(contractName);
                    }
                    if (org.apache.commons.lang.StringUtils.isNotBlank(buildName)) {
                        rwdextra.setBuildNameNew(buildName);
                    }
                    rwdextra.setIsAddInformation(rwdextraExtend.getIsAddInformation());
                    rwdextra.setRwdextraExtend(rwdextraExtend);
                }
            } catch (Exception e) {
                log.error("组装ERP任务单其它信息失败，直接返回不做任何处理！");
            }
        }
    }

    private void setCjOrGys(Integer config, MixProportionReport.BgxxInfo bgxxInfo) {
        String objId = bgxxInfo.getPktzid();
        if (objId == null || "".equals(objId) || "null".equals(objId)) {
            return;
        }
        Long experimentId = Long.valueOf(objId);
        /**试验台账信息*/
        Experiment experiment = experimentMapper.loadById(experimentId);
        String cjjc = experiment.getFactoryCalled();
        String cj = experiment.getFactory();
        String gysjc = experiment.getSupplyCompanyCalled();
        String gys = experiment.getSupplyCompanyName();
        if (config == 1) {
            bgxxInfo.setCj(StringUtils.isNotBlank(cjjc) ? cjjc : cj);
        } else if (config == 2) {
            bgxxInfo.setCj(StringUtils.isNotBlank(gysjc) ? gysjc : gys);
        }
        bgxxInfo.setBatch(experiment.getBatch());
        bgxxInfo.setXhbgbh(experiment.getReportNo());
        bgxxInfo.setCertificateNo(experiment.getCertificateNo());
    }

    private String setTestBlockNumber(String ypbh) {
        if (StringUtils.isNotBlank(ypbh)) {
            int length = ypbh.length();
            if (length > 3) {
                return ypbh.substring(ypbh.length() - 3);
            }
        }
        return "";
    }

    private String roundToOneDecimalPlace(String valueStr, int scale) {
        try {
            // 向上取整（RoundingMode.CEILING）
            BigDecimal ceilBd = new BigDecimal(valueStr)
                    .setScale(scale, RoundingMode.CEILING);
            if (scale == 0) {
                return String.valueOf(ceilBd.intValue());
            }
            return String.valueOf(ceilBd.doubleValue());
        } catch (NumberFormatException e) {
            // 如果字符串无法转换为数值，返回原始字符串
            return valueStr;
        }
    }

    /**
     * 根据服务类型获取磁盘路径
     * 默认是windows磁盘路径
     *
     * @return
     */
    public String getPathName() {
        String operSystem = MacTools.getOperSystem();
        if (Arrays.stream(BaseParams.MAC_LIST).parallel().anyMatch(operSystem::contains)) {
            return ADDRESS_MAC;
        } else if (Arrays.stream(BaseParams.LINUX_LIST).parallel().anyMatch(operSystem::contains)) {
            return ADDRESS_LINUX;
        }
        return ADDRESS_WINDOWS;
    }
}
